﻿using System.Security.Principal;
using Project.Domain.Entities;

namespace Framework.Admin
{
    public class EnhancedPrincipal : IPrincipal
    {
        private readonly IIdentity _identity;
        private readonly User _userData;
        public static readonly EnhancedPrincipal Anonymous = new AnonymousPrincipal();

        public EnhancedPrincipal(IIdentity identity, User userData)
        {
            _userData = userData;
            _identity = identity;
        }

        public bool IsInRole(string role)
        {
            return role == _userData.Roles && _userData.IsAdmin;
        }

        public IIdentity Identity
        {
            get { return _identity; }
        }

        public User Data
        {
            get { return _userData; }
        }

        private class AnonymousIdentity :IIdentity
        {
            public string Name
            {
                get { return "Anonymous"; }
            }

            public string AuthenticationType 
            {
                get { return null; }
            }

            public bool IsAuthenticated
            {
                get { return false; }
            }
        }

        private class AnonymousPrincipal : EnhancedPrincipal
        {
            public AnonymousPrincipal()
                : base(new AnonymousIdentity(), new User

                    {
                        UserId = 0,
                        UserName = "Anonymous"
                    })
            {

            }
        }

    }
}